package com.example.administrator.ksf_zty.util;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;


/**
 * Created by lihaidong on 2017/5/5 0005.
 */
public class HttpUtil {
    //OKHTTP的POST请求
    public static void sendOkHttpRequest(String address, RequestBody formBody, okhttp3.Callback callback) {
        OkHttpClient client = new OkHttpClient.Builder()
                .retryOnConnectionFailure(false)//避免重复发起请求,取消OKHTTP3重连机制
                .connectTimeout(30, TimeUnit.SECONDS)//连接超时时间设置为30秒
                .readTimeout(30, TimeUnit.SECONDS)//读写超时时间设置为30秒
                .build();
        Request request = new Request.Builder()
                .url(address)
                .post(formBody)
                .build();
        client.newCall(request).enqueue(callback);
    }

}
